//
//  WLDiskChartView.m
//  WanLian
//
//  Created by muzhuang on 2018/10/30.
//  Copyright © 2018年 wanlian. All rights reserved.
//

#import "WLDiskChartView.h"

@implementation WLDiskChartView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _labTotal = [[UILabel alloc]initWithFrame:CGRectMake(WLScaleX(30), (frame.size.height-WLScaleX(50))/2.0, frame.size.width-WLScaleX(60), WLScaleX(25))];
        _labTotal.font = [WLCommonTool fontTypePingFangSCMedium:14];
        _labTotal.textColor = wlDarkGrayColor;
        _labTotal.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_labTotal];
        
        _labShare = [[UILabel alloc]initWithFrame:CGRectMake(WLScaleX(30), CGRectGetMaxY(_labTotal.frame), frame.size.width-WLScaleX(60), WLScaleX(25))];
        _labShare.font = [WLCommonTool fontTypePingFangSCMedium:14];
        _labShare.textColor = wlDarkGrayColor;
        _labShare.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_labShare];
    }
    return self;
}



// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    float strart = (M_PI * 270)/ 180.0;
    float du = (_shareSize * 360) + 270;
    float hudu = (M_PI*(du > 360 ? (du - 360) : du))/180.0;
    
    UIBezierPath *Path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.frame.size.width / 2.f, self.frame.size.height / 2.f) radius:self.frame.size.height / 2.f - 30 startAngle:strart endAngle:hudu clockwise:YES];
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.path = Path.CGPath;
    layer.fillColor = [UIColor clearColor].CGColor;
    layer.strokeColor = wlblueColor.CGColor;
    layer.lineWidth = WLScaleX(20);
    [self.layer addSublayer:layer];
    
    float move = (M_PI * (_totalSize-_shareSize)*360)/ 180.0 + hudu;
    float stat = hudu;
    UIBezierPath *pathTwo = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.frame.size.width / 2.f, self.frame.size.height / 2.f) radius:self.frame.size.height / 2.f - 30 startAngle:stat endAngle:move clockwise:YES];
    CAShapeLayer *layerTwo = [CAShapeLayer layer];
    layerTwo.path = pathTwo.CGPath;
    layerTwo.fillColor = [UIColor clearColor].CGColor;
    layerTwo.strokeColor = wlUIColorRGB(0x2292F5).CGColor;
    layerTwo.lineWidth = WLScaleX(16);
    [self.layer addSublayer:layerTwo];
}


@end
